home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / ctrlalt.arc / CTRLALT.ASM < prev    next >
Assembly Source File  |  1988-06-29  |  38KB  |  1,318 lines

  1.                                  title CTRLALT
  2. cseg segment
  3.          assume cs:cseg, ds:cseg
  4.          org 100H
  5. begin:   jmp install
  6.          ascbuffer label byte
  7. db 13,'CTRLALT Version 1.00   April, 1986',13,10
  8. db       'Copyright R.M.Wilson and B.Simon',26
  9. ;--------------------------------------------------------------------------
  10. background = 1FH             ;    CHANGE COLORS
  11. mainattr = 30H               ;   HERE FOR ASCII
  12. border = 19H                 ;      TABLES  
  13. attrlabel=1BH
  14.  
  15. monobackground = 07H         ;    CHANGE MONOCHROME 
  16. monomainattr = 70H           ;        ATTRIBUTES
  17. monoborder = 0FH             ;           HERE
  18.  
  19. colxor = 2AH                 ; Attributes to XOR for highlighting
  20. monoxor = 77H                ;        for ^@P and ^@<Enter>
  21. asccolxor = 5FH              ;      ...and, respectively,
  22. ascmonoxor =  0FFH           ;     for ASCII tables (^@A and H).
  23.  
  24. colcopyattr = 1EH            ; When COPY command is used.  1EH=Yellow/Blue
  25. monocopyattr = 07H           ;         07H=White/Black
  26.  
  27. begoff = 246       ;Offset for upper left corner of decimal ASCII table.
  28. hexbegoff = 166    ;Ditto for hex.               
  29. attrbegoff= 1546   ;Ditto for Attribute table.
  30. ansibegoff= 1610   ;Ditto for ANSI table.
  31.  
  32. callcombo = 0CH    ;0CH for Ctrl-Alt, 06H for Ctrl-Shift, 0AH for Shift-Alt.
  33. ;------------------------------------------------------------------------
  34.               ;**** DEFAULTS
  35. attrchar   db 24      ;Character used initially by CTRL-ALT-T
  36. drawmode   dw 1       ;0-6   Initial mode for Box Drawing (ALT-NUMPAD). 
  37. drawdown   db 0       ;For Alt-Grey±:   1=dn/rt, 0=neutral, -1=up/lf
  38.               ;Following are for CTRL-ALT-I
  39. fastflag   db 0FFH    ;0 if slow, 0FFH if fast inserting is wanted.
  40. carretflag db 0FFH    ;0 if backspacing, 0FFH if carriage returns are wanted.
  41. ;-------------------------------------------------------------------------
  42.               ;**** SCAN CODES FOR COMMAND KEYS FOLLOW:
  43. commands db 1FH,2EH,25H,18H,1EH,19H,23H,43H
  44.          db 1CH,17H,10H,0CH,0DH,30H,12H
  45.          db 0BH,2,3,4,5,6,7
  46.          db 14H,13H,8,9,0AH
  47.          db 2FH,2CH,31H
  48.               ;**** CORRESPONDING SUBROUTINES TO JUMP TO:
  49. comaddr  dw  Switch,Copy,Kill,Otherasc,decAsc,Print,Hexasc,back2dos
  50.          dw  cUt,Insert,stopstart,slowspeed,fastspeed,Backsp,asciiEnter
  51.          dw  setdraw,setdraw,setdraw,setdraw,setdraw,setdraw,setdraw
  52.          dw  showaTtrs,carRets,setdrawup,unsetdrawdown,setdrawdown
  53.          dw  Vanilla,Zilch,showaNsi
  54. ;-------------------------------------------------------------------------
  55.               ;**** SCAN CODES FOR CTRL-ALT-P  SUBCOMMANDS FOLLOW:
  56. prtcoms db 1CH,19H,50H,48H,49H,51H,1EH,1,1FH,4FH,47H,13H
  57. begincodes label byte ;Control codes to prn only below.
  58.         db 30H,11H,2EH,20H,14H,3H,16H,9H
  59.         db 25H,2,21H,12H,17H,10H,31H,18H
  60.               ;**** CORRESPONDING SUBROUTINES TO JUMP TO:
  61. prtaddr dw enter,enter,dnarr,uparr,pgup,pgdn,all,esc,pswitch,pend,phome,reset
  62. codeaddr dw bold,wide,cond,dstrike,tiny,charset2,underline,lf8   
  63.          dw skipperf,unidir,topform,emph,pica,qual,newpage,alloff
  64. ;-------------------------------------------------------------------------
  65.               ;**** SCAN CODES FOR CTRL-ALT-ENTER SUBCOMMANDS FOLLOW:
  66. cutcoms db   16H,50H,48H,4DH,4BH,1H,52H,1CH,17H,37H
  67.         db   19H,49H,51H,4EH,4AH,2EH,1FH,47H,4FH
  68.         db   12H
  69.               ;**** CORRESPONDING SUBROUTINES TO JUMP TO:
  70. cutaddr dw ccut,cdnarr,cuparr,crtarr,clfarr,cesc,tack,tack,immenter,prtbox
  71.         dw prtbox,cpgdn,cpgup,cgplus,cgminus,ccopy,cswitch,home,end
  72.         dw immenter
  73. ;-------------------------------------------------------------------------
  74.               ;**** SCAN CODES FOR CTRL-ALT-A/H SUBCOMMANDS FOLLOW:
  75. asccoms db  30H,12H,48H,50H,4DH,4BH,37H,19H,1
  76.         db  47H,4FH,1CH
  77.               ;**** CORRESPONDING SUBROUTINES TO JUMP TO:
  78. ascaddr dw  ascbuff,ascins,ascup,ascdn,ascrt,asclf,ascprn,ascprn,ascesc
  79.         dw  aschome,ascend,ascins
  80. ;------------------------------------------------------------------------------
  81. bold        db  27,69,27,71,0FFH    ;emph & double strike          
  82. dstrike     db  27,71,0FFH
  83. underline   db  27,45,1,0FFH
  84. tiny        db  27,83,1,27,65,5,27,50,15,0FFH
  85. lf8         db  27,48,0FFH
  86. charset2    db  27,54,0FFH
  87. cond        db  15,0FFH
  88. wide        db  27,87,1,0FFH
  89. skipperf    db  27,78,8,0FFH
  90. unidir      db  27,85,1,0FFH
  91. topform     db  12,0FFH
  92. emph        db  27,69,0FFH
  93. pica        db  27,58,0FFH    ;proprinter
  94. qual        db  27,73,2,0FFH  ;proprinter
  95. newpage     db  27,52,0FFH    ;proprinter
  96. alloff      db  27,70,27,72,18,27,87,0,27,84,27,79,27,55
  97.             db  27,45,0,27,65,12,27,50,27,73,0,13,0FFH
  98. ;####################################################################
  99.          oldvec = 5CH
  100.          oldtvec= 60H
  101. ;####################################################################
  102. on_flag  db 0   ;1--Marking, 2--^@P
  103. myint:   push ax                       ;Replacement for Interrupt 9.
  104.          push ds
  105.          sub ax,ax
  106.          mov ds,ax
  107.          mov al,ds:[417H]
  108.          and al,0FH            
  109.          cmp al,callcombo             
  110.          je readport
  111.          cmp al,8  ;alt      
  112.          jne exit
  113.          cmp cs:drawmode,0
  114.          je exit
  115.          in al,60H
  116.          sub al,47H
  117.          jc exit
  118.          cmp al,11
  119.          ja exit
  120.          jmp draw
  121. readport:in al,60H ;Read port to see what happened.
  122.          push bp
  123.          cld
  124.          xor bp,bp
  125.          ck:cmp al, cs:commands[bp]
  126.          je lets_go
  127.          inc bp
  128.          cmp bp,offset comaddr - offset commands ;number of commands
  129.          jl ck 
  130.          pop bp
  131. exit:    pop ds
  132.          pop ax
  133.          jmp dword ptr cs:[oldvec]     
  134. lets_go: push es
  135.          push bx
  136.          push cx
  137.          push dx
  138.          push si
  139.          push di
  140.          call reset_keyboard
  141.          shl bp,1
  142.          jmp cs:comaddr[bp]
  143. reset_keyboard:
  144.          cli
  145.              in al,61H    ;This stuff is necessary for PC and XT  
  146.              mov ah,al    ;...could be omitted for AT.            
  147.              or al,80H 
  148.              out 61H,al
  149.              xchg ah,al
  150.              out 61H,al
  151.          mov al,20H
  152.          out 20H,al
  153.          sti                      
  154.          ret
  155. ;==========================================
  156. back2dos:mov ah,4CH
  157.          int 21H
  158. ;==========================================
  159. vanilla: mov ax,0B000H
  160.          mov es,ax
  161.          mov al,7
  162.          jmp short l34
  163. copy:    call aim
  164.          rep movsw
  165.          l34:mov di,1
  166.          mov cx,2000
  167.          clr:stosb
  168.          inc di
  169.          loop clr
  170.          jmp short endint
  171. kill:    call aim
  172.          mov ax,720H
  173.          rep stosw
  174.          jmp short endint
  175.                      aim: mov cx,2000   ;Sets cx,es,ds,si=di=0,al,xorattr
  176.                           mov ax,0B000H
  177.                           xor si,si
  178.                           xor di,di
  179.                           mov ds,di
  180.                           mov bl,byte ptr ds:[410H]
  181.                           mov ds,ax
  182.                           mov es,ax
  183.                           add ah,8H
  184.                           test bl,10H
  185.                           je cmon
  186.                           mov es,ax
  187.                           mov cs:xorattr,monoxor 
  188.                           mov al,colcopyattr
  189.                           ret
  190.                      cmon:mov ds,ax       ;color monitor in use
  191.                           mov cs:xorattr,colxor
  192.                           mov al,monocopyattr
  193.                           ret
  194. ;==========================================
  195. endint:  pop di
  196. endint2: pop si
  197.          pop dx
  198.          pop cx
  199.          pop bx
  200.          pop es
  201.          pop bp
  202.          pop ds
  203.          pop ax
  204.          iret
  205. ;==============================
  206. switch:  call aim ; sets si,di,cx,bl
  207.          push bx  ;  get cursor
  208.          push cx
  209.          mov ah,3
  210.          xor bh,bh
  211.          int 10H
  212.          mov ch,20H   ;turn off cursor
  213.          mov ah,1
  214.          int 10H
  215.          pop cx
  216.          pop bx
  217.          push ds
  218.          mov ds,di
  219.          xor bl,10H
  220.          mov ds:[410H],bl
  221.          pop ds
  222.          mov ax,3
  223.          int 10H
  224.          xor di,di             
  225.          rep movsw
  226.          mov ah,2   ;set cursor at dx
  227.          xor bh,bh
  228.          int 10H
  229.          jmp endint
  230. ;==========================================
  231. xorxor = colxor XOR monoxor
  232. xorattr db 44H
  233. print:   test cs:on_flag,2
  234.          je ov274
  235.          jmp endint
  236.          ov274:or cs:on_flag,2
  237.          xor dx,dx
  238.          mov ah,2
  239.          int 17H
  240.          test ah,8
  241.          jne badprn
  242.          test ah,20H
  243.          je ov678
  244.          badprn:mov ax,0E07H
  245.          int 10H
  246.          jmp esc
  247.          ov678:call aim
  248.          push ds
  249.          pop es
  250.          xor bh,bh
  251.          mov ah,3
  252.          int 10H     ;dh is cursor row
  253.          mov ax,160
  254.          mul dh
  255.          mov dx,ax
  256.          inc dx
  257.          mov bp,1    ;number of marked rows
  258. marknwait:call mark
  259.          xor ah,ah
  260.          int 16H
  261.          call mark
  262.          xor bx,bx
  263.          comp:cmp ah, cs:prtcoms[bx]
  264.          je gotcom
  265.          inc bx
  266.          cmp bx,offset prtaddr -offset prtcoms    ;no. of commands
  267.          jl comp
  268.          jmp marknwait
  269. gotcom:  cmp bx,offset begincodes - offset prtcoms 
  270.          jge sendcodes 
  271.          shl bx,1
  272.          jmp cs:prtaddr[bx]
  273. sendcodes:push si
  274.          push dx
  275.          sub bx,offset begincodes - offset prtcoms
  276.          shl bx,1
  277.          mov si,cs:codeaddr[bx]
  278.          xor dx,dx       
  279.       more:xor ah,ah      
  280.          mov al,cs:[si]  
  281.          inc si          
  282.          cmp al,0FFH     
  283.          je done2        
  284.          int 17H         
  285.          jmp more        
  286. reset:   push si
  287.          push dx
  288.          xor dx,dx
  289.          mov ah,1
  290.          int 17H
  291.      done2:pop dx
  292.          pop si
  293.          jmp marknwait
  294. pend:    mov ax,bp
  295.          mov dx,1+160*25
  296.          mov bl,160
  297.          mul bl
  298.          sub dx,ax
  299.       jmw:jmp marknwait
  300. phome:   mov dx,1
  301.          jmp marknwait
  302. pswitch: mov ax,es   
  303.          xor ah,8H
  304.          mov es,ax
  305.          xor cs:xorattr,xorxor
  306.          jmp marknwait
  307. dnarr:   inc bp
  308.          mov bx,bp
  309.          mov ax,160
  310.          mul bl
  311.          add ax,dx
  312.          cmp ax,4160
  313.          jle jmw
  314.          dec bp
  315.          jmp marknwait
  316. uparr:   dec bp
  317.          jne jmw
  318.          inc bp
  319.          jmp marknwait
  320. pgup:    sub dx,160
  321.          jge jmw
  322.          add dx,160
  323.          jmp marknwait
  324. pgdn:    mov ax,bp
  325.          mov bl,160
  326.          mul bl
  327.          add ax,dx
  328.          cmp ax,4000
  329.          jg jmw
  330.          add dx,160
  331.          jmp marknwait
  332. all:     mov dx,1
  333.          mov bp,25
  334. enter:   push es   ;start si-1 offset, do bp lines
  335.          pop ds
  336.          mov si,dx
  337.          xor dx,dx
  338.          dec si
  339.          mn:mov cx,80
  340.          up9:lodsb
  341.          xor ah,ah
  342.          mov bl,al    ;Filter out ASCII 0-1F, 80-9F.
  343.          and bl,7FH
  344.          cmp bl,20H
  345.          jae ov134
  346.          mov al,20H
  347.          ov134:int 17H
  348.          inc si
  349.          loop up9
  350.          mov ax,0DH
  351.          int 17H
  352.          mov ax,0AH
  353.          int 17H
  354.          dec bp
  355.          jne mn
  356. esc:     and cs:on_flag,0FDH
  357.          jmp endint
  358.                      mark:  mov si,bp
  359.                             mov di,dx
  360.                             mov al,cs:xorattr
  361.                             up3:mov cx,80
  362.                             up4:xor byte ptr es:[di],al
  363.                             inc di
  364.                             inc di
  365.                             loop up4
  366.                             dec si
  367.                             jnz up3
  368.                             ret
  369. ;=====================================================
  370. numrows dw 0
  371. numcols dw 0
  372. upleft  dw 0
  373. screen dw 0B800H
  374. showattrs:
  375.          cmp cs:asciionflag,0
  376.          je ov76
  377.          jmp ei
  378.          ov76:mov cs:asciionflag,'T'
  379.          mov cs:upleft,attrbegoff
  380.          call attrsetup
  381.          call fewhexnos
  382.          wt:call attrdisplay
  383.          xor ah,ah
  384.          int 16H
  385.          cmp ah,1H
  386.          je ov39
  387.          mov di,attrbegoff+12
  388.          mov cs:attrchar,al
  389.          mov dx,ax    ;save
  390.          mov si, offset scan
  391.          mov ah,attrlabel
  392.          call write4
  393.          call hexndec
  394.          mov di,attrbegoff+1610
  395.          mov si,offset ascii
  396.          mov cx,5
  397.          call write
  398.          mov dh,dl
  399.          call hexndec
  400.          jmp wt
  401.          ov39:jmp restore
  402. hexndec: inc di
  403.          inc di
  404.          mov bh,dh
  405.          call showbx
  406.          mov al,'H'
  407.          stosw
  408.          add di,4
  409.          mov al,dh
  410.          call decshowal
  411.          ret
  412. write4:  mov cx,4
  413. write:   lods byte ptr cs:[si]
  414.          stosw
  415.          loop write
  416.          ret
  417. scan db 'Scan'
  418. ascii db 'Ascii'
  419. otherasc:call aim
  420.          push es
  421.          pop cs:screen
  422.          push cs:upleft
  423.          push cs:numrows
  424.          push cs:numcols
  425.          call decload
  426.          call monoclear    ;and border
  427.          call display
  428.          call hexload
  429.          call monoclear    ;and border
  430.          call hexdisplay
  431.          pop cs:numcols
  432.          pop cs:numrows
  433.          pop cs:upleft
  434.          ei:jmp endint
  435. decasc:  cmp cs:asciionflag,0
  436.          jne ei
  437.          call aim
  438.          push ds
  439.          pop cs:screen
  440.          call decload
  441.          call savenclear       ;and border
  442.          call display          ;and numbers
  443.          jmp asciiwait 
  444. hexasc:  cmp cs:asciionflag,0
  445.          jne ei
  446.          call aim
  447.          push ds
  448.          pop cs:screen
  449.          call hexload
  450.          call savenclear       ;and border
  451.          call hexdisplay       ;and hexnums
  452.          jmp asciiwait 
  453. decload: mov cs:upleft,begoff
  454.          mov cs:numrows,15
  455.          mov cs:numcols,34
  456.          ret
  457. hexload: mov cs:upleft,hexbegoff
  458.          mov cs:numrows,19
  459.          mov cs:numcols,22
  460.          ret
  461. savenclear: mov ax,cs:screen
  462.          mov ds,ax
  463.          push cs
  464.          pop es
  465.          mov di,offset store
  466.          mov si,cs:upleft      ;save
  467.          mov bp,cs:numrows
  468.          up81:mov cx,cs:numcols
  469.          rep movsw
  470.          add si,160
  471.          sub si,cs:numcols
  472.          sub si,cs:numcols
  473.          dec bp
  474.          jnz up81
  475.     monoclear:mov ax,cs:screen
  476.          mov es,ax
  477.          mov di,cs:upleft            ;background and ascii chars
  478.          mov bp,cs:numrows                   ; no. of rows
  479.          mov al,20H
  480.          mov ah,background
  481.          cmp cs:screen,0B000H
  482.          jne row
  483.          mov ah,monobackground
  484.          row:mov cx,cs:numcols
  485.          rep stosw
  486.          add di,160
  487.          sub di,cs:numcols
  488.          sub di,cs:numcols
  489.          dec bp
  490.          jnz row
  491.          mov ax,cs:numcols    ;Do border.
  492.          dec ax
  493.          dec ax
  494.          shl ax,1
  495.          mov bx,ax    ;colb
  496.          neg ax
  497.          add ax,156
  498.          mov dx,ax    ;rest
  499.          mov di,cs:upleft
  500.          mov ah, border
  501.          cmp cs:screen,0B000H
  502.          jne ov737
  503.          mov ah,monoborder
  504.          ov737:mov al,201
  505.          stosw
  506.          call horiz
  507.          mov al,187
  508.          stosw
  509.          mov di,cs:upleft
  510.          mov cx,cs:numrows
  511.          dec cx
  512.          dec cx
  513.          mov al,186
  514.          add di,160
  515.          up0:stosw
  516.          add di,bx  ;colb
  517.          stosw
  518.          add di,dx  ;rest
  519.          loop up0
  520.          mov al,200
  521.          stosw
  522.          call horiz
  523.          mov al,188
  524.          stosw
  525.          ret
  526.    horiz:   mov cx,cs:numcols
  527.             dec cx
  528.             dec cx
  529.             mov al,205
  530.             rep stosw
  531.             ret
  532. ;=========================
  533. attrdisplay:
  534.          xor bl,bl
  535.          mov di,cs:upleft
  536.          add di,328
  537.          mov bp,8
  538.          mov al,cs:attrchar
  539.          wrr:call eightattr
  540.          inc di
  541.          inc di
  542.          call eightattr
  543.          add di,126
  544.          dec bp
  545.          jnz wrr
  546.          ret 
  547.            eightattr:mov cx,8
  548.                    ffff:mov ah,bl
  549.                    cmp cs:asciionflag,'N'
  550.                    jne ov764
  551.                         push bx    ;This routine converts ah to 'ansi'
  552.                         mov bl,ah 
  553.                         and bx,0FH
  554.                         mov dl,cs:ansiperm[bx]
  555.                         push cx
  556.                         mov cl,4
  557.                         shr ah,cl
  558.                         mov bl,ah
  559.                         mov ah,cs:ansiperm[bx]
  560.                         shl ah,cl
  561.                         pop cx
  562.                         add ah,dl
  563.                         pop bx
  564.                    ov764:stosw
  565.                    inc bl
  566.                    loop ffff
  567.                    ret             
  568. ;----------------------------------------------------
  569. attrsetup:call aim
  570.          push ds
  571.          pop cs:screen
  572.          mov cs:numrows,11                       
  573.          mov cs:numcols,22
  574.          call savenclear   ;and border
  575.          ret
  576. showansi:
  577.          cmp cs:asciionflag,0
  578.          je ov732
  579.          jmp ei
  580.          ov732:mov cs:asciionflag,'N'
  581.          mov cs:upleft,ansibegoff
  582.          call attrsetup
  583.          mov di,168+ansibegoff
  584.          mov ah,2
  585.          up333:mov cx,8
  586.          mov al,'0'
  587.          up891:stosb
  588.          inc di 
  589.          inc al
  590.          loop up891
  591.          inc di
  592.          inc di
  593.          dec ah
  594.          jne up333
  595.          mov di,322+ansibegoff   
  596.          mov cl,8
  597.          mov al,'0'
  598.          up99:mov byte ptr es:[di],'4'
  599.          inc di
  600.          inc di
  601.          stosb
  602.          add di,157
  603.          inc al
  604.          loop up99
  605.          add di,18
  606.          mov ah,attrlabel 
  607.          mov si,offset ansilabel
  608.          call write4 
  609.          mov di,12+ansibegoff
  610.          mov si,offset ansihead1
  611.          call write4
  612.          add di,10
  613.          mov si,offset ansihead2
  614.          call write4
  615.          call attrdisplay
  616.          xor ah,ah
  617.          int 16H
  618.          jmp restore
  619. ansihead1  db '0;3x'
  620. ansihead2  db '1;3x'
  621. ansilabel  db 'ANSI'
  622. ansiperm   db 0,0100B,0010B,0110B,0001B,0101B,0011B,0111B
  623.            db 1,1100B,1010B,1110B,1001B,1101B,1011B,1111B  
  624. ;======================================================
  625. display: xor bl,bl          ;char counter
  626.          mov di,cs:upleft
  627.          add di,170
  628.          mov bp,13
  629.       writeasc:
  630.          call fivech
  631.          call fivech
  632.          add di,10
  633.          call fivech
  634.          call fivech
  635.          add di,102
  636.          dec bp
  637.          jnz writeasc
  638. numbers:     ;for ASCII table
  639.          mov di,begoff+166
  640.          mov cl,13
  641.          mov al,'0'
  642.          call numtype
  643.          mov di,begoff+164
  644.          mov cl,13
  645.          up55:stosb
  646.          add di,33
  647.          inc al
  648.          stosb
  649.          add di,125
  650.          inc al
  651.          cmp al,39H
  652.          jle ok
  653.          sub al,10
  654.          ok:loop up55
  655.          mov di,begoff+162
  656.          mov cl,5
  657.          mov al,30H
  658.          call numtype
  659.          mov cl,5
  660.          inc al
  661.          call numtype
  662.          inc al
  663.          mov cl,3
  664.          call numtype
  665.          ret 
  666.              numtype:stosb
  667.                 add di,33
  668.                 stosb
  669.                 add di,125
  670.                 loop numtype
  671.                 ret
  672. hexdisplay:mov bl,0
  673.          mov di, cs:upleft
  674.          add di,328
  675.          mov bp,16
  676.          wr:call eightch
  677.          call eightch
  678.          add di,124
  679.          dec bp
  680.          jnz wr
  681. hexnumbers:mov di,168+hexbegoff
  682.          call puthexhead
  683.          mov di,322+hexbegoff
  684.          mov si,offset hexheader
  685.          mov cx,16
  686.          up112:movs es:byte ptr[di], cs:[si]
  687.          inc di
  688.          mov byte ptr es:[di],'0'
  689.          add di,158
  690.          loop up112
  691.          ret
  692.                         eightch:mov cx,8
  693.                         jmp short ov898
  694.                         fivech:mov cx,5
  695.                         ov898:mov ah,mainattr
  696.                         cmp cs:screen,0B000H
  697.                         jne ov899
  698.                         mov ah,monomainattr
  699.                         ov899:mov al,bl
  700.                         stosw
  701.                         inc bl
  702.                         loop ov899
  703.                         inc di
  704.                         inc di
  705.                         ret
  706. fewhexnos:mov di,168+attrbegoff
  707.          call puthexhead
  708.          mov di,322+attrbegoff   
  709.          mov cx,8
  710.          mov al,'0'
  711.          up02:stosb
  712.          inc di
  713.          mov byte ptr es:[di],'0'
  714.          add di,158
  715.          inc al
  716.          loop up02
  717.          ret
  718. puthexhead:mov cx,8
  719.          mov si,offset hexheader
  720.          ytr:movs es:byte ptr[di], cs:[si]
  721.          inc di
  722.          loop ytr
  723.          inc di
  724.          inc di
  725.          mov cl,8
  726.          lp9:movs es:byte ptr[di], cs:[si]
  727.          inc di
  728.          loop lp9
  729.          ret
  730. hexheader db '0123456789ABCDEF'
  731.                       showbx:mov cx,2   ;cx 4 or 2 shows bx or bh
  732.                              llp:rol bx,1
  733.                              rol bx,1
  734.                              rol bx,1
  735.                              rol bx,1
  736.                              push bx
  737.                              and bx,000FH
  738.                              mov al,cs:hexheader[bx]
  739.                              mov ah,attrlabel
  740.                              stosw
  741.                              pop bx
  742.                              loop llp
  743.                              ret
  744.                    decshowal:    ;converts al to decimal
  745.                              aam
  746.                              mov bl,al
  747.                              or bl,'0'             
  748.                              xchg al,ah            
  749.                              aam
  750.                              or ax,'00'            
  751.                              mov dh,al             
  752.                              mov al,ah             
  753.                              mov ah,attrlabel      
  754.                              stosw                 
  755.                              mov al,dh             
  756.                              stosw                 
  757.                              mov al,bl             
  758.                              stosw                 
  759.                              ret                   
  760. ;--------------------------------------------------------------------------
  761. asciicuroff dw begoff+171
  762. asciihexcuroff dw  hexbegoff+329
  763. asciionflag db 0
  764. ascbuffptr dw 0
  765. asciitowrite db 0                    ;flag
  766. asciiwait:mov cs:asciionflag,0FFH    ;set it
  767.          mov cs:buffflag,0
  768.          mov di,cs:asciicuroff
  769.          mov ax,es
  770.          cmp cs:upleft,begoff
  771.          je ov734
  772.          mov di,cs:asciihexcuroff
  773.          ov734:mov bh,asccolxor
  774.          mov ax,ds
  775.          cmp ah,0B8H ;color?
  776.          je amark
  777.          mov bh,ascmonoxor
  778.     amark:cmp cs:upleft, begoff
  779.          je ov87
  780.          mov cs:asciihexcuroff,di
  781.          jmp short ov88
  782.          ov87:mov cs:asciicuroff,di
  783.          ov88:xor es:[di],bh
  784.          xor ah,ah
  785.          int 16H
  786.          xor es:[di],bh
  787.          xor bp,bp
  788.          asccomp:cmp ah,cs:asccoms[bp]
  789.          je ascgotcom
  790.          inc bp
  791.          cmp bp,offset ascaddr - offset asccoms ;no. of commands
  792.          jl asccomp
  793.          jmp amark
  794. ascgotcom:shl bp,1
  795.          jmp cs:ascaddr[bp]
  796. ascup:   sub di,160          ;UpArr
  797.          ch2:or di,di
  798.          jge amark
  799.          add di,160 
  800.          jmp short amark
  801. ascdn:   add di,160          ;DnArr
  802.          ch1:cmp di,4000
  803.          jl amark
  804.          sub di,160
  805.          jmp short amark
  806. ascrt:   inc di            ;RtArr
  807.          inc di
  808.          jmp short ch1
  809. asclf:   dec di
  810.          dec di            ;LfArr
  811.          jmp short ch2
  812. aschome: cmp cs:upleft,begoff
  813.          je ov91
  814.          mov di,hexbegoff+329    
  815.          jmp amark
  816.          ov91:mov di,begoff+171  
  817.          jmp amark
  818. ascend:  cmp cs:upleft,begoff
  819.          je ov92
  820.          mov di,hexbegoff+329+2432    
  821.          jmp amark
  822.          ov92:mov di,begoff+329+1816    
  823.          jmp amark
  824. ascins:  cmp cs:buffflag,0
  825.          jne ov71                      
  826.          mov cs:ascbuffptr,0
  827.          ov71:call getasc
  828.          mov cs:ascwriteptr,0
  829.          mov cs:asciitowrite,0FFH      ;set it
  830.          mov cs:worktodoflag,0FFH
  831. ascesc:  jmp restore
  832. ascprn:  xor dx,dx            ;PrtSc
  833.          xor ah,ah
  834.          mov al,es:[di-1]
  835.          int 17H
  836.          jmp amark
  837. asciienter:mov cs:ascwriteptr,0
  838.          mov cs:asciitowrite,0FFH    ;set it
  839.          mov cs:worktodoflag,0FFH
  840.          jmp endint
  841. buffflag db 0
  842. ascbuff: cmp cs:buffflag,0
  843.          jne ov36
  844.          not cs:buffflag
  845.          mov cs:ascbuffptr,0
  846.          ov36:call getasc
  847.          jmp amark
  848. getasc:  mov al,es:[di-1]          ;get char from screen; put in buffer
  849.          mov bp,cs:ascbuffptr      ;location for next char
  850.          cmp bp,64
  851.          jl ov23
  852.          pop ax 
  853.          jmp restore
  854.          ov23:mov byte ptr cs:ascbuffer[bp],al
  855.          inc cs:ascbuffptr
  856.          ret
  857. ascwriteptr dw 0                                        
  858. ent2:    mov bx,cs:ascwriteptr
  859.          mov al,cs:ascbuffer[bx]    
  860.          xor ah,ah                  ;Move word (char. and scan code)
  861.          mov word ptr ds:[bp],ax    ;into buffer and
  862.          mov ds:[1CH],cx            ;change buffer tail pointer.
  863.          inc cs:ascwriteptr
  864.          inc bx
  865.          cmp bx,cs:ascbuffptr
  866.          jge ov13
  867.          jmp send
  868.          ov13:mov cs:asciitowrite,0
  869.          jmp done
  870. ;----------------------------------------------------------------------
  871. restore: push cs
  872.          pop ds
  873.          mov si,offset store
  874.          mov di,upleft 
  875.          mov bp,numrows
  876.          up65:mov cx,numcols
  877.          rep movsw
  878.          add di,160
  879.          sub di,numcols
  880.          sub di,numcols
  881.          dec bp
  882.          jnz up65
  883.          mov asciionflag,0
  884.          jmp endint
  885. ;=========================================================================
  886. stopstart:not cs:worktodoflag    
  887.          jmp endint
  888. slowspeed:mov cs:fastflag,0
  889.          jmp endint
  890. fastspeed:mov cs:fastflag,0FFH
  891.          jmp endint
  892. backsp:  mov cs:carretflag,0
  893.          jmp endint
  894. carrets: mov cs:carretflag,0FFH
  895.          jmp endint
  896. zilch:   mov cs:carretflag,'Z' 
  897.          jmp endint
  898. ;--------------------------------
  899. stuffptr dw 0
  900. tnumrows dw 0
  901. rowptr dw 0
  902. tnumcols dw 0
  903. colptr dw  0
  904. worktodoflag db 0
  905. goingbackflag db 0
  906. downflag db 0
  907. docrflag db 0
  908. timeint: cmp cs:worktodoflag,0  
  909.          je tend
  910.          cld 
  911.          sti
  912.          push ds
  913.          push cx
  914.          push bx
  915.          push ax
  916.          push bp
  917.          mov bp,40H
  918.          mov ds,bp
  919. loo:     mov bp,ds:[1CH]
  920.          mov cx,bp
  921.          inc cx
  922.          inc cx
  923.          cmp cl,3EH
  924.          jl ov
  925.          sub cl,20H
  926.       ov:cmp cx,ds:[1AH]
  927.          je send                  ;If equal, buffer full; exit.
  928.          cmp cs:asciitowrite,0
  929.          je ov9
  930.          jmp ent2
  931.          ov9:cmp cs:stuffptr,0    
  932.          je done                  
  933.          call getword             ;Else, move word (char. and scan code)
  934.          mov word ptr ds:[bp],ax  ;     into buffer and
  935.          mov ds:[1CH],cx          ;     change buffer tail pointer.
  936.          cmp cs:rowptr,0
  937.          je done
  938.          cmp cs:stuffptr,0 
  939.          jle done
  940.          cmp cs:fastflag,0
  941.          jz send
  942.          jmp loo
  943. done:    mov cs:worktodoflag,0
  944. send:    pop bp
  945.          pop ax
  946.          pop bx
  947.          pop cx
  948.          pop ds
  949. tend:    jmp dword ptr cs:[oldtvec] 
  950. getword: cmp cs:carretflag,'Z'
  951.          jne b99
  952.          xor ah,ah
  953.          mov bx,cs:stuffptr
  954.          mov al,cs:stuff[bx]
  955.          dec cs:stuffptr
  956.          ret 
  957.          b99:cmp cs:docrflag,0       ;See if we need a Carriage Return.
  958.          je b0
  959.          mov cs:docrflag,0
  960.          mov ax,1C0DH
  961.          jmp b6 
  962.          b0:cmp cs:downflag,0        ;See if we need a DownArrow.
  963.          je b1
  964.          mov cs:downflag,0
  965.          mov ax,5000H     ;DnArr
  966.          b6:mov bx,cs:tnumcols                
  967.          mov cs:colptr,bx
  968.          rr:ret
  969.          b1:cmp cs:goingbackflag,0   ;See if we need LeftArrow.
  970.          je b2
  971.          mov ax,4B00H     ;LfArr
  972.          dec cs:colptr
  973.          jne rr   
  974.          mov cs:downflag,0FFH  ;Need a down next.
  975.          mov cs:goingbackflag,0
  976.          ret
  977.          b2:xor ah,ah          ;Get character from stuff.
  978.          mov bx,cs:stuffptr   
  979.          mov al,cs:stuff[bx]
  980.          dec cs:stuffptr
  981.          dec cs:colptr
  982.          jnz rr
  983.          dec cs:rowptr         ;Another row to do if this not zero.
  984.          jz rr
  985.          cmp cs:carretflag,0
  986.          je b3
  987.          mov cs:docrflag,0FFH
  988.          ret
  989.          b3:mov cs:goingbackflag,0FFH   ;go back 
  990.          mov bx,cs:tnumcols                
  991.          mov cs:colptr,bx
  992.          ret 
  993. ;=====================================================
  994. prtbox:  call setup        ;bp=no.cols, cx=no.rows
  995.          mov bx,cx
  996.          dec si            ;offset to begin
  997.          xor dx,dx
  998.          up71:mov cx,bp
  999.        lp6:lodsb
  1000.          mov ah,0
  1001.          int 17H
  1002.          inc si
  1003.          loop lp6
  1004.          mov ax,0DH
  1005.          int 17H
  1006.          mov ax,0AH
  1007.          int 17H
  1008.          add si,160
  1009.          sub si,bp
  1010.          sub si,bp
  1011.          dec bx
  1012.          jnz up71
  1013.          jmp cesc
  1014. ;========================================================
  1015. ccopy:   call setup   ;cx no. rows, bp no. cols
  1016.          dec si
  1017.          mov di,si
  1018.         lp08:mov dx,bp  ;no. cols
  1019.         up13:movsb
  1020.          inc di
  1021.          inc si
  1022.          dec dx
  1023.          jnz up13
  1024.          add si,160
  1025.          sub si,bp
  1026.          sub si,bp
  1027.          mov di,si
  1028.          loop lp08
  1029.          jmp cesc
  1030. ;----------------------------------------------
  1031. cswitch: push es
  1032.          push ds
  1033.          pop es
  1034.          pop ds
  1035.          xor cs:xorattr,xorxor
  1036.          jmp cmarknwait
  1037. ;----------------------------------------------------
  1038. immenter:call cccut
  1039.          and cs:on_flag,0FEH
  1040. insert:  cli
  1041.          push cs
  1042.          pop ds
  1043.          mov worktodoflag,0FFH
  1044.          mov asciitowrite,0
  1045.          mov bx,tnumcols
  1046.          mov colptr,bx
  1047.          mov ax,tnumrows
  1048.          mov rowptr,ax
  1049.          mul bl
  1050.          mov stuffptr,ax 
  1051.          mov goingbackflag,0
  1052.          mov downflag,0
  1053.          sti
  1054.          jmp endint
  1055. ;------------------------------------------------------
  1056. beginflag db 0
  1057. cut:     test cs:on_flag,1
  1058.          je ov284
  1059.          jmp endint
  1060.          ov284: or cs:on_flag,1
  1061.          mov cs:beginflag,0
  1062.          call aim     ;ds points to screen
  1063.          mov ah,3
  1064.          xor bh,bh
  1065.          int 10H      ;cursor row, col in dx  (upper left of box)
  1066.          mov bx,dx    ;bx contains row, col of lower right
  1067. cmarknwait:call markbox
  1068.          xor ah,ah
  1069.          int 16H
  1070.          push ax
  1071.          call markbox
  1072.          pop ax
  1073.          xor bp,bp
  1074.          ccomp:cmp ah,cs:cutcoms[bp]
  1075.          je gotcutcom
  1076.          inc bp
  1077.          cmp bp,offset cutaddr - offset cutcoms  ;no. of commands 
  1078.          jl ccomp
  1079.          jmp cmarknwait
  1080. gotcutcom:shl bp,1
  1081.          jmp cs:cutaddr[bp]
  1082. cdnarr:  cmp bh,24
  1083.          jge j1
  1084.          inc bh
  1085.          cmp cs:beginflag,0
  1086.          jne j1
  1087.          mov dx,bx
  1088.          j1:jmp cmarknwait
  1089. cuparr:  cmp cs:beginflag,0
  1090.          jne ov6
  1091.          or bh,bh
  1092.          je j1
  1093.          dec bh
  1094.          dec dh
  1095.          jmp cmarknwait
  1096.          ov6:cmp bh,dh
  1097.          jle j1
  1098.          dec bh
  1099.          jmp cmarknwait
  1100. crtarr:  cmp bl,79
  1101.          jge j1
  1102.          inc bl
  1103.          cmp cs:beginflag,0
  1104.          jne j1
  1105.          mov dx,bx
  1106.          jmp cmarknwait
  1107. clfarr:  cmp cs:beginflag,0
  1108.          jne ov7
  1109.          or bl,bl
  1110.          je j1
  1111.          dec bl
  1112.          dec dl
  1113.          jmp cmarknwait
  1114.          ov7:cmp bl,dl
  1115.          jle j1
  1116.          dec bl
  1117.          jmp cmarknwait
  1118. home:    sub bx,dx
  1119.          xor dx,dx
  1120.          jmp cmarknwait
  1121. end:     mov ax,184FH
  1122.          sub ax,bx
  1123.          add bx,ax
  1124.          add dx,ax
  1125.          jmp cmarknwait
  1126. tack:    cmp cs:beginflag,1
  1127.          je ccut
  1128.          mov cs:beginflag,1
  1129.          jcm:jmp cmarknwait
  1130. ccut:    call cccut
  1131. cesc:    and cs:on_flag,0FEH
  1132.          jmp endint
  1133.      cccut:
  1134.          call setup   ;bp=no.cols, cx=no.rows
  1135.          mov cs:tnumrows,cx
  1136.          mov cs:tnumcols,bp
  1137.          mov bx,cx
  1138.          dec si               ;offset to begin
  1139.          mov di,offset stuff         
  1140.          mov ax,bp
  1141.          mul bl
  1142.          mov cs:stuffptr,ax   ;no.chars
  1143.          add di,ax
  1144.          mm:mov al,ds:[si]
  1145.          mov cs:[di],al
  1146.          dec di
  1147.          inc si
  1148.          inc si
  1149.          dec bp
  1150.          jnz mm
  1151.          mov bp,cs:tnumcols
  1152.          add si,160
  1153.          sub si,bp
  1154.          sub si,bp
  1155.          loop mm
  1156.          ret
  1157. cpgdn:   or dh,dh
  1158.          je jcm
  1159.          dec dh
  1160.          dec bh
  1161.          jmp cmarknwait
  1162. cpgup:   cmp bh,24
  1163.          je jcm
  1164.          inc dh
  1165.          inc bh
  1166.          jmp cmarknwait
  1167. cgplus:  cmp bl,79
  1168.          je  jcm
  1169.          inc bl
  1170.          inc dl
  1171.          jmp cmarknwait
  1172. cgminus: or dl,dl
  1173.          je jcm
  1174.          dec dl
  1175.          dec bl
  1176.          jmp cmarknwait
  1177.                    markbox:  call setup
  1178.                              mov al,cs:xorattr
  1179.                              nextrw:mov di,bp
  1180.                              xx:xor byte ptr ds:[si],al
  1181.                              inc si
  1182.                              inc si
  1183.                              dec di
  1184.                              jnz xx
  1185.                              add si,160
  1186.                              sub si,bp
  1187.                              sub si,bp
  1188.                              loop nextrw
  1189.                              ret
  1190.                     setup:   mov al,dh    ;start rows
  1191.                              mov cl,dh
  1192.                              mov bp,dx    ;bp=start col in low byte
  1193.                              and bp,0FFH
  1194.                              mov ch,160   
  1195.                              mul ch       ;ax contains offset of start,but..
  1196.                              xor ch,ch    ;cx=start rows
  1197.                              mov si,ax
  1198.                              inc si
  1199.                              push dx
  1200.                              xor dh,dh
  1201.                              add si,dx
  1202.                              add si,dx    ;offset to start
  1203.                              pop dx
  1204.                              neg bp
  1205.                              add bp,bx
  1206.                              and bp,0FFH
  1207.                              inc bp       ;no.cols to mark
  1208.                              push bx
  1209.                              xchg bh,bl
  1210.                              xor bh,bh
  1211.                              sub bx,cx
  1212.                              inc bx        
  1213.                              mov cx,bx    ;no. of rows
  1214.                              pop bx
  1215.                              ret
  1216. ;--------------------------------------------------------------------------
  1217. setdraw: shr bp,1
  1218.          sub bp,15  
  1219.          mov cs:drawmode,bp
  1220.          jmp endint
  1221. drawchars db  '┌┬┐─├┼┤│└┴┘'
  1222.           db  '╔╦╗═╠╬╣║╚╩╝'
  1223.           db  '╒╤╕═╞╪╡│╘╧╛'
  1224.           db  '╓╥╖─╟╫╢║╙╨╜'
  1225.           db  '▌▐▀«█■▄»░▒▓'
  1226.           db  'αßτΓδεΘΣµπσ'
  1227. draw:    cli
  1228.          push bp           
  1229.          push es           
  1230.          push bx           
  1231.          push cx           
  1232.          push dx
  1233.          push si
  1234.          mov bl,al        ;between 0 and 10
  1235.          mov dl,al        ;save it here too
  1236.          call reset_keyboard
  1237.          mov ax,cs:drawmode
  1238.          mov si,ax        ;store drawmode
  1239.          dec ax     
  1240.          mov cl,11
  1241.          mul cl           ;ax contains 11 times drawmode-1
  1242.          add bl,al
  1243.          xor bh,bh
  1244.          mov al,cs:drawchars[bx]
  1245.          mov bp,40H
  1246.          mov ds,bp
  1247.          call put_ax
  1248.          cmp si,4   ;check drawmode
  1249.          ja ov54
  1250.          or si,si
  1251.          je ov54
  1252.          cmp cs:drawdown,1
  1253.          jne ov57
  1254.          cmp dl,7
  1255.          jne ov54 
  1256.          mov ax,4B00H 
  1257.          call put_ax 
  1258.          mov ah,50H 
  1259.          call put_ax
  1260.          jmp short ov54
  1261.          ov57:cmp cs:drawdown,-1
  1262.          jne ov54
  1263.          cmp dl,7
  1264.          jne ov58
  1265.          mov ax,4B00H
  1266.          call put_ax
  1267.          mov ah,48H
  1268.          call put_ax
  1269.          jmp short ov54
  1270.          ov58:cmp dl,3
  1271.          jne ov54
  1272.          mov ax,4B00H
  1273.          call put_ax     
  1274.          call put_ax
  1275.          ov54: 
  1276.          jmp endint2 
  1277. put_ax:  mov bp,ds:[1CH]
  1278.          mov cx,bp
  1279.          inc cx
  1280.          inc cx
  1281.          cmp cx,3EH
  1282.          jl ov8
  1283.          sub cx,20H     
  1284.       ov8:cmp cx,ds:[1AH]
  1285.          je ov721                 ;If equal, buffer full; exit.
  1286.          mov word ptr ds:[bp],ax  ;Else, move word (char. and scan code)
  1287.          mov ds:[1CH],cx          ;into buffer and change buffer tail pointer.  
  1288.          ov721:ret
  1289. setdrawdown:mov cs:drawdown,1
  1290.          jmp endint
  1291. unsetdrawdown:mov cs:drawdown,0
  1292.          jmp endint
  1293. setdrawup:mov cs:drawdown,-1
  1294.          jmp endint
  1295. ;----------------------------------------------------------------------------
  1296. store    label word              ;dw 510 dup ()
  1297. stuff    = offset store +1020    ;db 2001 dup ()
  1298. ;##############################################################################
  1299. install: mov ax,3509H                   ;9 is keyboard interrupt
  1300.          int 21H                        ;get old int vector
  1301.          mov word ptr cs:[oldvec],bx    ;and save it
  1302.          mov word ptr cs:[oldvec+2],es
  1303.          mov dx,offset myint
  1304.          mov ax,2509H                   ;set new int vector with ds:dx
  1305.          int 21H    
  1306.          mov ax,3508H                   ;timer interrupt
  1307.          int 21H                        ;get old int vector
  1308.          mov word ptr cs:[oldtvec],bx   ;and save it
  1309.          mov word ptr cs:[oldtvec+2],es
  1310.          mov dx, offset timeint
  1311.          mov ax,2508H                   ;set new int vector with ds:dx
  1312.          int 21H    
  1313.          mov dx,offset install          ;prepare to leave resident
  1314.          add dx,3021
  1315.          int 27H
  1316. cseg ends
  1317. end begin
  1318.